
<%-- <jsp:directive.page session="true"/> --%>
<jsp:useBean id="register" class="dasregistry.registryBean" scope="page"/>
<jsp:useBean id="coord" class="dasregistry.coordBean" scope="page"/>
<!--<jsp:useBean id="traffic" class="dasregistry.TrafficLightBean" />-->
<jsp:directive.page import="dasregistry.dasClientLink"/>
<jsp:directive.page import="org.biojava.services.das.dao.ProjectBean"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasSource"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.Das1Source"/>
<jsp:directive.page import="org.biojava.dasobert.dasregistry.DasCoordinateSystem"/>
<jsp:directive.page import="org.biojava.services.das.registry.DasClient"/>
<jsp:directive.page import="org.biojava.services.das.registry.AutoActivation" />
<jsp:directive.page import="dasregistry.ActivationURLCreator" />
<jsp:directive.page import="java.lang.Integer"/>
<jsp:directive.page import="java.util.Date"/>
<jsp:directive.page import="java.util.Map"/>
<jsp:directive.page import="java.util.Set"/>
<jsp:directive.page import="java.util.List"/>
<jsp:directive.page import="java.util.Iterator"/>
<jsp:directive.page import="java.net.URL"/>
<jsp:directive.page import="java.text.SimpleDateFormat"/>
<%@ page import="org.biojava.dasobert.das.Capabilities"%>
<%@ page import="org.biojava.services.das.dao.Role" %>
<%@ page import="org.biojava.services.das.dao.RegistryUser" %>
<%@ page import="org.biojava.services.das.registry.UserManager" %>
<jsp:directive.page import="org.biojava.services.das.registry.DasRegistrySql" />
<jsp:directive.page import="org.springframework.beans.factory.BeanFactory"/>
<jsp:directive.page import="org.springframework.context.support.ClassPathXmlApplicationContext"/>

<% String title = "DAS source details" ;
   String header = title;
%>

<%@ include file="sangerheader.jsp" %>

<%
// fetch by auto id
   String auto_id = request.getParameter("auto_id");
   DasSource ds = register.getDasSource(auto_id);
   ActivationURLCreator activCreator = new ActivationURLCreator();
	
   
   if ( ds == null ) {
   	ds = new Das1Source();
   }   
   
		BeanFactory ctx=(new ClassPathXmlApplicationContext("SpringDAO.xml"));
		DasRegistrySql registry=(DasRegistrySql)ctx.getBean("registryBean");
	
	int db_auto_id = registry.getAutoID4DasSource(ds);
	
	boolean isOwner = false;
	if ( coord.userOwnsASource(user,new DasSource[]{ds})) {
		isOwner = true;
	}

	RegistryUser[] owners = coord.getOwnersForSource(ds);
	
%>


<div id="main">

<h2>Details for <%= ds.getNickname()%> </h2>

<script type="text/javascript">
<!--	

function submitAction(){
	
	var theForm = document.getElementById('dassourceaction');
	
	
	var ok = confirmation();
	if ( ok )
		theForm.submit();
		
	
}

function confirmation() {
	var answer = confirm("Are you sure you want to delete this DAS source?")
	if (answer){
		return true;	
	}
	else{
		return false;
	}
}//--></script>


<jsp:include page="openwindowscript.jsp" />

<p>

<%@ include file="sangertablestart.jsp" %>

 	 
 	 
<%
		int twodays = 1000*60*60*24*2 ;
		Date now = new Date();
		boolean active = true;
		if (ds.getLeaseDate().getTime() < ( now.getTime() - twodays)){
			active = false;
			%>
			<tr class="row2"><td colspan="2">
			 <div title="header=[server down?] body=[it was not possible to validate this server in > 2 days]">
				<img src="img/messagebox_warning.png"/>
				<b>It has not been possible to validate this server for > 2 days.</b>
			</div>
			
				
			</td>  <td>&nbsp;</td></tr>
			<%
		}

	DasClient[] clients = ActivationURLCreator.CONFIG_DAS_CLIENTS;	
	String testCode = "";
	DasCoordinateSystem[] coordSys = ds.getCoordinateSystem();
	if ( coordSys.length > 0 ) 
	   testCode = coordSys[0].getTestCode();
	String url = ds.getUrl();
	String nickname = ds.getNickname();
	
 	 
 	 %>
 	 
 	 <tr class="row0"><td colspan = "2">
<% if (isOwner){ %>
	<div title="header=[owner] body=[I am owner of this DAS source]"><img src="img/kuser.png"/></div>
	<%} %>


	 <%
		  boolean iconDisplayed = false ;
	 	  for (int j=0;j<coordSys.length;j++){
		      DasCoordinateSystem dcs = coordSys[j];
		      String org = dcs.getOrganismName();
		      if ( (! org.equals("")) && (iconDisplayed == false)) {
				 org = org.replaceAll(" ","_");
			 String thumbnail = "http://www.ensembl.org/img/species/thumb_";			
			 thumbnail += org;
			 thumbnail += ".png";
			 iconDisplayed = true;
		      	%><div title="header=[organism] body=[<%=org %>]"><img src="<%=thumbnail%>" valign="bottom"> <%
		      }
		   }
	  %>

		      <b><%=ds.getUrl()%></b></div></td>
		      
		      <td align="right">
		      <div title="header=[XML description] body=[this will show you the XML description of this DAS source.]">
		      <a href="das1/sources/<%=ds.getId() %>">
		      <img src="img/minixml.gif"/></a>
		      </div></td></tr>
	

	 <tr class="row1">
	     <td>unique id</td>
	     <td><%=ds.getId()%></td>
	     <td>&nbsp;</td>
	 </tr>


	  <tr class="row2">
	     <td>nickname</td>
	     <td><%=ds.getNickname()%></td>
	     <td>&nbsp;</td>
	 </tr>


<tr class="row1"><td>display in DAS clients</td>
    <td>
    
<%

	 List<String> capabs = ds.getCapabilities();
	 boolean canFeatures = false;	      		   
	 for (int j=0;j<capabs.size();j++){
	       String capability = capabs.get(j) ;
	       if ( capability.equals("features"))
		  canFeatures = true;
	}
	

	if ( canFeatures && active ) {
	 
		AutoActivation[] aas = activCreator.getAllActivationURLs(ds.getUrl());
		
		for (int l = 0 ; l < aas.length ; l++){
			
			AutoActivation aa = aas[l];
			DasClient client = aa.getClient();
			%>
			<div title="header=[activate in das client] body=[folow this link to activate this DAS source in the DAS client <%=client.getName() %>]">
			<a href="<%=aa.getURL(ds)%>"><%
			
			
			if ( client.getIconPath() != null ){
				out.print("<img src=\"" + client.getIconPath() + "\" border=\"0\"/> ");
			} 
			%> <%=client.getName() %></a> (<%= aa.getCoordSys().getTestCode() %>)
			</div><%
		}	
		
	}
	
	
	if ( isOwner ) {
		%><br/><a href="editAutoActivationUrl.jsp?auto_id=<%=ds.getId()%>">
		<img src="img/pencil16x16.png">
		edit links</a> <%
	}
	
%>
	</td>
	<td>&nbsp;</td>
	</tr>


	<tr class="row2"><td>description</td><td><%=ds.getDescription()%></td><td>&nbsp;</td></tr>
	<tr class="row1"><td>adminemail</td><td><%

	String sourceEmail = ds.getAdminemail();
	String e = sourceEmail.replaceAll("@","_AT_");
	out.print(e);

	%></td>
    <td>&nbsp;</td>
	</tr>
	<% String helperurl = ds.getHelperurl(); %>
	<tr class="row2"><td>helperurl</td><td>
	<% if ((helperurl!= null)&&( ! helperurl.equals(""))) { %>
	<a href="javascript:openWindow('<%=helperurl%>','',400,400)"><%=helperurl%></a>
	<% } %>	
	</td><td>&nbsp;</td></tr>
	
	<tr class="row1"> <td> DAS Capabilities: </td>
	 <td>
	 
		<%@ include file="showCapabilityLink.jsp"%>						
	</td><td>&nbsp;</td></tr>


	<tr class="row2"><td> Coordinate Systems: </td>
	  <td><% 
		      for (int j=0; j< coordSys.length;j++){
		      	DasCoordinateSystem dcs = coordSys[j];	
		      	%><a href="coordsys/<%=dcs.getUniqueId() %>"><%=dcs.toString()%></a><% 
		      	out.println(" testregion:" + dcs.getTestCode()+"<br/>");
		      }		 
	%></td><td>&nbsp;</td></tr>

		 
	<tr class="row1"> 
	<td>Registered on</td> 
	<td><%
		 SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");
		 Date d = ds.getRegisterDate() ;
		 out.print(df.format(d));
		 df = null ;
		 d = null ;
		 %>
	</td><td>&nbsp;</td>
	</tr>
	<tr class="row2"><td>Last tested successfully on: </td>
	<td><%
		 SimpleDateFormat df2 = new SimpleDateFormat("yyyy.MM.dd");
		 Date d2 = ds.getLeaseDate()  ;  
		 out.print(df2.format(d2));
		 df2 = null ;
		 d2 = null ;
		 %>
	</td><td>&nbsp;</td>
	</tr>

	<tr class="row1">
	<td> label(s)</td>
	<td>
	<%
		String[] labels = ds.getLabels();
	  	for (int j=0;j<labels.length;j++){
			String label = labels[j];
			out.print(label+" ");
		}
	%>
	</td><td>&nbsp;</td>
	</tr>


	<tr class="row2">
	<td> Project:
	</td>
	<td>
	<%
	ProjectBean project = coord.getProjectBeanForURL(ds.getUrl());
	if ( project != null ) {
		%>
		<div title="header=[<%=project.getName()%>] body=[<%=project.getDescription() %>]">
		<a href="showProjectDetails.jsp?project_id=<%=project.getProjectID() %>">
		<img src="<%=project.getIconURL()%>"/>
		<%=project.getName()%></a></div> 
		<%
		
		URL projectURL = project.getHomepage();
		if ( projectURL != null ) {		
		%><div title="header=[go to project homepage] body=[<%=project.getHomepage() %>]"><a href="<%=projectURL %>">go to homepage</a></div>
		
		<% 
		} else {
			%><%=project.getName()%><% 
		}
	} else {
		%> 
		
		 no project has been assigned, yet.<br/> 
		<% if ( isOwner ) {%> 
		<a href="addSourceProject.jsp?DS_ID=<%=ds.getId() %>"><img src="img/thumbnail.png"> assign to project</a>
		<%} %>
		
		<%
	}
	%>
	</td>
	<td>&nbsp;</td>
	</tr>
	
	
	<tr class="row1">
	<td> Owner:
	</td>
	<td>
	
	<%
	
	
	
	for (int i =0 ; i< owners.length; i++){
		RegistryUser owner = owners[i];
		%>
		<%= owner.getEmail() %><br/>
		<% 
		if ( user.equals(owner)) {
			%>
			<img src="img/kuser.png"/> <a href="claimSources.jsp?cmd=share&DS_ID=<%=ds.getId() %>"/>share ownership</a><br/>
			<%
		}		
		
		
	}		
	%>
	
	
	<%	if ((owners.length == 0 ) &&
			(email != null) &&
			(! isOwner)) { %>
	

	<a href="claimSources.jsp?DS_ID=<%=ds.getId()%>"><img src="img/kuser32x32.png" border="0" align="bottom"> claim ownership</a> of this server. (das source admin only)
	
<%} %>
	
	</td>
	<td>&nbsp;</td>
	</tr>
	
	



<%--

	Map m = traffic.getServerStatus(ds.getUrl());
	if ( m.keySet().size() > 4 ) {
		%>

	<tr id="row1">
	<td> traffic lights</td>
	<td><table>
	<%
		Set keys = m.keySet();
		Iterator iter = keys.iterator();
		while (iter.hasNext()) {
			String key = (String)iter.next();
			String val = (String)m.get(key);			
			%><tr><td align="right"><%=key%></td><td align="right"><img src="img/<%=val%>.png"/></td></tr><%			
		}
	%></table>
	</td>
	</tr>
		<%
	}


--%>

	

	<tr class="row2">
	<td> &nbsp;</td>
	<td>
	<a href="sendToFriend.jsp?auto_id=<%=ds.getId()%>"><img src="img/mail_post_to.png" border="0" align="bottom"> send this das source</a> to a friend.
	</td><td>&nbsp;</td>
	</tr>

	<tr class="row1">
	<td> &nbsp;</td>
	<td>
	<a href="validateServer.jsp?auto_id=<%=ds.getId()%>"><img src="img/validate.png" border="0" align="bottom"> validate</a> server.
	</td><td>&nbsp;</td>
	</tr>


	<tr class="row2">
	<td> &nbsp;</td>
	<td>
	<a href="editServer.jsp?auto_id=<%=ds.getId()%>"><img src="img/pencil32x32.png" border="0" align="bottom"> edit</a> this server. (das source admin only)
	</td><td>&nbsp;</td>
	</tr>

	<tr class="row1">
	<td> &nbsp;</td>
	<td>
	
    <form id="dassourceaction" name="dassourceaction" action="DasSourceAction" method="POST" >
	<input type="hidden" name="action" value="delete"/>
	<input type="hidden" name="DS_ID"  value="<%=ds.getId() %>"/>
	
	<%--<input type="image" src="img/edit_remove.png" alt="remove" />--%>
	
	<%-- <a onClick="submitAction(this.form.action);"> --%>
	<a href="javascript: submitAction()">
	<img src="img/edit_remove.png" border="0" align="bottom">  
	remove </a> this server. (das source admin only)
	<%-- 
	
	 <a href="removeServer.jsp?url=<%=ds.getUrl()%>" onChange="submitAction(this.form.action);"><img src="img/edit_remove.png" border="0" align="bottom"> remove</a> this server. (das source admin only)--%>
	</form>
	</td><td>&nbsp;</td> 
	</tr>

<%-- <tr id="row1">
	<td>History:</td>
	<td>
	This DAS source superseds another DAS source:
	
< % 
if ( isOwner) {
% >
	
	<img src="img/pencil16x16.png" border="0" align="bottom">

	< %
	
	DasSource[] sources = registry.getServicesForemail(email);
	% >
	<form action=""/>
	< %
	for (DasSource source : sources ) {
		% >
		< %=source.getId() %> <%=source.getNickname() %></br>
		< % 
	}
	% >
	</form>
< %} % >

	
	</td><td>&nbsp;</td>
	</tr>
	
--%>
	

<%@ include file="sangertableend.jsp" %>

    
<br/>
<br/>
    
<!-- statistics on server - had to take out at the moment as uses sessions-->
<%-- <%@taglib uri='/WEB-INF/cewolf.tld' prefix='cewolf' %> --%>
     
<%-- <jsp:useBean id="dasSourceUptimeStat" class="org.biojava.services.das.cewolf.DasSourceUptimeStat" scope="session"/>         --%>
<!-- <cewolf:chart   -->
<!--     id="timeChart"   -->
<!--     title="server uptime statistics"  -->
<!--     type="verticalXYBar"  -->
<!--     xaxislabel="time"  -->
<!--     yaxislabel="availability"  -->
<!--     > -->
<!--     <cewolf:data> -->
<!--         <cewolf:producer id="dasSourceUptimeStat" usecache="true">  -->
<%-- 			<cewolf:param name="ds_id" value="<%=ds.getId()%>"/> --%>
<%-- 			<cewolf:param name="time" value="<%=new java.util.Date()%>"/> --%>
<!-- 		</cewolf:producer> -->
<!--     </cewolf:data> -->
  
<!-- </cewolf:chart> -->
<!-- <cewolf:img chartid="timeChart" renderer="cewolf" width="400" height="300"/> -->
</div>
<script src="boxover.js"></script>
<%@ include file="sangerfooter.jsp" %>

	


